<template>
  <el-card class="box-card">
    <!-- 搜索框 -->
    <!-- <div slot="header" class="clearfix">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="姓名" class="movement">
          <el-input
            v-model="formInline.name"
            placeholder="请输入姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号" class="movement">
          <el-input
            v-model="formInline.phone_number"
            placeholder="请输入手机号"
            class="movement"
          ></el-input>
        </el-form-item>
        <el-form-item label="工种" class="movement">
          <el-select v-model="formInline.names" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search()" class="movement"
            >查询</el-button
          >
          <el-button type="primary" @click="reset()" class="movement"
            >重置</el-button
          >
          <el-button type="primary" @click="addYuanGongs()">新增员工</el-button>
        </el-form-item>
      </el-form>
    </div> -->
    <!-- 列表展示 -->
    <div>
      <el-table
        v-loading="loading"
        :data="tableData"
        border
        style="width: 100%"
        max-height="600"
      >
        <el-table-column
          label="序号"
          align="center"
          type="index"
          :index="indexMethod"
          width="70"
        >
        </el-table-column>
        <el-table-column prop="nickname" align="center" label="用户名名称">
        </el-table-column>
        <el-table-column prop="name" align="center" label="姓名">
        </el-table-column>
        <!-- <el-table-column
          show-overflow-tooltip
          prop="img"
          align="center"
          label="头像"
        >
          <template slot-scope="scope">
            <el-image
              style="width: 50px; height: 50px"
              :src="scope.row.img"
              fit="cover"
            ></el-image>
          </template>
        </el-table-column> -->

        <el-table-column prop="phone" align="center" label="电话">
        </el-table-column>
        <el-table-column prop="Identity_id" align="center" label="身份证号">
        </el-table-column>
        <el-table-column prop="is_status" align="center" label="状态">
          <template slot-scope="scope">
            <span>{{
              scope.row.status == 0
                ? "待审核"
                : scope.row.status == 1
                ? "同意"
                : scope.row.status == 2
                ? "拒绝"
                : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.status == 2 || scope.row.status == 0"
              type="success"
              size="mini"
              @click="handleEdit(scope.row)"
              >同意</el-button
            >
            <el-button
              v-if="scope.row.status == 1"
              type="danger"
              size="mini"
              @click="handleEdit(scope.row)"
              >拒绝</el-button
            >
            <!-- <el-button
              v-if="scope.row.is_status === 2"
              type="danger"
              size="mini"
              @click="deleteUser(scope.row)"
              >删除</el-button
            > -->
            <el-button type="warning" size="mini" @click="compile(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-sizes="[10, 100, 200, 300]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <!-- 新增/编辑员工 -->
    <el-dialog
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
      :title="titleText"
    >
      <el-form :model="formLabelAlign" label-width="85px" ref="form">
        <!-- <p class="addP" @click="add">新增员工</p> -->
        <div class="oneLine">
          <el-form-item label="姓名">
            <div>{{ formLabelAlign.name }}</div>
            <!-- <el-input
              v-model="formLabelAlign.name"
              placeholder="请输入姓名"
            ></el-input> -->
          </el-form-item>
        </div>
        <div class="oneLine">
          <el-form-item label="电话">
            <div>{{ formLabelAlign.phone }}</div>
            <!-- <el-input
              v-model="formLabelAlign.phone_number"
              placeholder="请输入电话号码"
            ></el-input> -->
          </el-form-item>
        </div>

        <div class="oneLine">
          <el-form-item label="身份证号">
            <div>{{ formLabelAlign.Identity_id }}</div>
            <!-- <el-input
              v-model="formLabelAlign.phone_number"
              placeholder="请输入身份证号"
            ></el-input> -->
          </el-form-item>
        </div>
        <div class="oneLine">
          <el-form-item label="身份证类型">
            <div>{{ formLabelAlign.Identity_type_text }}</div>
            <!-- <el-input
              v-model="formLabelAlign.phone_number"
              placeholder="请输入身份证号"
            ></el-input> -->
          </el-form-item>
        </div>
        <div class="oneLine">
          <el-form-item label="身份证信息" prop="imageUrl">
            <div class="IDCard">
              <div>
                <el-image
                  style="width: 200px; height: 140px"
                  :src="imgHeader + formLabelAlign.identity_positive"
                  fit="fit"
                  :preview-src-list="[
                    imgHeader + formLabelAlign.identity_positive,
                  ]"
                ></el-image>
                <p>身份证人像面</p>
              </div>
              <div>
                <el-image
                  style="width: 200px; height: 140px"
                  :src="imgHeader + formLabelAlign.identity_reverse"
                  fit="fit"
                  :preview-src-list="[
                    imgHeader + formLabelAlign.identity_reverse,
                  ]"
                ></el-image>
                <p>身份证国徽面</p>
              </div>
            </div>
          </el-form-item>
        </div>
      </el-form>
      <div class="btnBox">
        <el-button type="danger" dialogVisible @click="reject">拒绝</el-button>
        <el-button type="success" dialogVisible @click="agree">同意</el-button>
      </div>
    </el-dialog>
  </el-card>
</template>

<script>
import {
  getPersonalAuthentication,
  getPersonalAuthenticationDetail,
} from "../../../utils/main";
export default {
  data() {
    return {
      options: [
        {
          value: "kanchayuan",
          label: "勘察员",
        },
      ],
      options1: [
        {
          id: "1",
          name: "材料费+工时费",
        },
        {
          id: "2",
          name: "工时费",
        },
      ],
      options2: [
        {
          id: "1",
          name: "白班",
        },
        {
          id: "2",
          name: "夜班",
        },
      ],
      value: "",
      loading: false,
      token: sessionStorage.getItem("token"),
      formInline: {
        name: "",
        phone_number: "",
        names: "",
      },
      imgHeader: this.Global.imgHeader,

      //新增员工弹框
      titleText: "",
      dialogVisible: false,
      currentPage: 1,
      total: 0,
      limit: 10,
      page: 1,
      name: "",
      authority_id: "3,4",
      phone_number: "",
      user_skill: "",
      names: "",
      type: "1",
      // authority_id: 5,
      tableData: [],
      //新增员工
      formLabelAlign: {
        name: "",
        phone_number: "",
        jiguan: "",
        gonling: "",
        names: "",
        img: "123",
        authority_id: "3,4",
        type: "",
        proportion: "",
      },
      //上传图片
      imageUrl: "",
      fileList: [],
      fileType: ["png", "jpg", "jpeg"],
      fileLimit: 1,
      headers: { "Content-Type": "multipart/form-data" },
    };
  },
  methods: {
    //关闭弹框
    handleClose(done) {
      done();
      // this.clearData();
    },
    //分页器
    //每页多少条
    handleSizeChange(val) {
      this.limit = val;
      this.getList();
    },
    //第几页
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    // 获取个人审核认证列表数据
    async getList() {
      this.loading = true;
      let res = await getPersonalAuthentication(
        this.token,
        this.page,
        this.limit
      );
      if (res.data.status) {
        this.tableData = res.data.data.data || [];
        this.total = res.data.data.count;
        // console.log(this.tableData.list, "55555");
        let timer = setTimeout(() => {
          this.loading = false;
          clearTimeout(timer);
        }, 400);
      } else {
        if (res.data.message == "token失效,请重新进行登录") {
          this.$router.push("/login");
        }
        if (res.data.message == "此账号没有权限") {
          this.$message.error(res.data.message);
          this.loading = false;
        }
        let timer = setTimeout(() => {
          this.$message.error(res.data.message);
        }, 5000);
      }
    },

    // 序号排序
    indexMethod(index) {
      if (this.total < this.limit) {
        return this.total - index;
      } else {
        return this.total - (this.page - 1) * this.limit - index;
      }
    },

    // 同意拒绝
    conditionUser(id, status) {
      getPersonalAuthenticationDetail(this.token, id, status)
        .then((res) => {
          if (res.data.status) {
            this.getList();
            this.dialogVisible = false;
          } else {
            if (res.data.message == "token失效,请重新进行登录") {
              this.$router.push("/login");
            }
            if (res.data.message == "此账号没有权限") {
              this.$message.error(res.data.message);
              this.loading = false;
            }
            let timer = setTimeout(() => {
              this.$message.error(res.data.message);
            }, 5000);
          }
        })
        .catch((err) => {
          console.log(err.message);
        });
    },
    // 同意拒绝
    handleEdit(row) {
      if (row.status == 0) {
        let is_status = 1;
        this.conditionUser(row.id, is_status);
      }
      if (row.status == 1) {
        let is_status = 2;
        this.conditionUser(row.id, is_status);
      }
      if (row.status == 2) {
        let is_status = 1;
        this.conditionUser(row.id, is_status);
      }
    },
    // 弹出层里的同意
    agree() {
      let is_status = 1;
      this.conditionUser(this.formLabelAlign.id, is_status);
    },
    // 弹出层里的拒绝
    reject() {
      let is_status = 2;
      this.conditionUser(this.formLabelAlign.id, is_status);
    },

    // 详情
    compile(row) {
      // let obj = JSON.stringify(row);
      // console.log(obj);
      this.formLabelAlign = row;
      if (row.Identity_type == 1) {
        this.formLabelAlign.Identity_type_text = "身份证";
      } else if (row.Identity_type == 2) {
        this.formLabelAlign.Identity_type_text = "港澳居民来往内地通行证";
      } else if (row.Identity_type == 3) {
        this.formLabelAlign.Identity_type_text = "台湾居民来往内地通行证";
      }
      console.log(this.formLabelAlign);
      this.dialogVisible = true;
    },
  },
  mounted() {
    this.getList();
  },
};
</script>

<style scoped>
.movement {
  margin-right: 10px;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.oneLine {
  display: flex;
  justify-content: space-between;
  /* margin-bottom: 14px; */
}
.addP {
  font-size: 22px;
  text-align: center;
  margin-bottom: 10px;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.unlodBox {
  display: flex;
}
.btnBox {
  display: flex;
  justify-content: center;
}
.IDCard {
  display: flex;
}
.IDCard div {
  margin-right: 10px;
}
</style>